package com.psw.monitor.geserialport;

import com.psw.monitor.geserialport.config.SerialPortManager;
import org.springframework.boot.CommandLineRunner;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration;
import org.springframework.scheduling.annotation.EnableScheduling;

import javax.annotation.PreDestroy;

@EnableScheduling
@SpringBootApplication(exclude = DataSourceAutoConfiguration.class)
public class GeSerialPortApplication implements CommandLineRunner {

    public static void main(String[] args) {
        SpringApplication.run(GeSerialPortApplication.class, args);
    }

    @Override

    public void run(String... args) throws Exception {
        try {
            SerialPortManager.connectSerialPort("ch340");
        } catch (Exception e) {
            System.out.println(e.toString());
        }

    }

    @PreDestroy
    public void destroy() {
        SerialPortManager.closeSerialPort();
    }
}

